<?php

require_once __CFG_PATH_LIBS . __CFG_PATH_CORE."mail.php";

$ErrorMessages = array();

if(!isEmptyArr($_POST) && $_POST['task'] == 'send')
{  if(!preg_match("/^".$CONFIG['emailPattern']."$/", $_POST['email']))
  {
  	$ErrorMessages[] = $ERRORS['contacts'][__ERROR_INCORRECT_EMAIL];
  }
  if(isBlank($_POST['name']) || isBlank($_POST['message']))
  {
  	$ErrorMessages[] = $ERRORS['contacts'][__ERROR_EMPTY_REQUIRED_FIELDS];
  }
  if(isBlank($_POST['code']) || $_POST['code'] != getSecurityNumber())
  {
  	$ErrorMessages[] = $ERRORS['contacts'][__ERROR_INCORRECT_SECURITY_CODE];
  }
  if(isEmptyArr($ErrorMessages))
  {
    $toDBArr['language'] = $CLIENT['sitelanguage'];
    unset($toDBArr['date']);
    unset($toDBArr['task']);
    unset($toDBArr['code']);
    unset($toDBArr['message']);
    userSubscribe($toDBArr, $Errors);

    $toRepl = array('sitename' => $CONFIG['SiteName']);
    replaceVariables($toRepl, $MailSubject['contacts']['contactForm']);

    sendMailToUser(array($CONFIG['adminEmail'],$CONFIG['adminBCCEmail']), $MailSubject['contacts']['contactForm'], stripslashes(nl2br($_POST['message'])), null, $_POST['name'], $_POST['email']);
    showMessageAlertJVSC($language['contacts']['thankYouForYourMessage']);
    go_toJVSC(getPath()."contacts".$CONFIG['webPageFileType']);
    exit;
  }
}

  $Article = getRowByFields($_SQL_TABLE['article'], array("id = '7'", "active = 'y'"));
  $Article['title'] = $Article['title'.__FLANG];
  $Article['body'] = $Article['body'.__FLANG];
  $tpl->assign("Article", $Article);


  $tpl->assign("MetaKeywords", $Article['meta_keywords'.__FLANG]);
  $tpl->assign("MetaDescription", $Article['meta_description'.__FLANG]);
  $tpl->assign("MetaTitle", $Article['meta_title'.__FLANG]);


$tpl->assign("POST", $_POST);
$tpl->assign("article", $article);
$tpl->assign("ErrorMessages", $ErrorMessages);
$tpl->assign("task", $_POST['task']);

$tpl->assign("PageTitle", $language['contacts']['contactUs']);

$_BODY_SMARTY_TEMPLATE = $CONFIG['ModulesFolder']."module.contacts.tpl";

?>